package com.woniuxy.bank_a.service.impl;


import com.woniuxy.bank_a.feign.BankbService;
import com.woniuxy.bank_a.mapper.BankaMapper;
import com.woniuxy.bank_a.service.BankaService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author: 15489  <br/>
 * Date: 2022/4/1:10:07  <br/>
 * Description:
 */
@Service
public class BankaServiceImpl implements BankaService {
    @Resource
    private BankaMapper bankaMapper;
    @Resource
    private BankbService bankbService;

    @Override
    @GlobalTransactional //全局事务 ，只需要在事务的发起方开启就行
    public int update(int id, int money) {
//        1:调用对方的接口 先让对方操作
       Boolean result= bankbService.start(2001,money);


//        2：根据对方的结果 决定当前微服务的操作
        if(result){
            bankaMapper.update(1001,100);
                int a=1/0;
        }
        return 0;
    }
}
